import request, { uploadRequest } from "./request";
import type { Common, SignTeam, UserSign } from '@/api/data';

type UploadImageBodyType = { tempFilePaths: any[]; formData?: Record<string, any> };

/**
 * 对接外部h5
 * Outside
 */
// 获取token信息
export const accessGetToken = (data: Partial<{ token: string; invite_code: string }>) =>
  request<{ token: string }>('/h5/get_token', 'POST', data);


// 上传图片
export const uploadImage = (data: UploadImageBodyType) =>
  uploadRequest<{ url: string }>('/common/upload', data.tempFilePaths, data?.formData);
// 校验身份证图片
export const check_ocr_identity = (front_img: string) =>
  request<Common.CheckOcrIdentity.Data>('/common/check_ocr_identity', 'POST', { front_img });

// 报名配置
export const userSignConfig = () => request<UserSign.Config.Data>('/user_sign/config', 'GET');
// 报名人列表
export const userSignIndex = () => request<UserSign.Index.Data[]>('/user_sign/index', 'GET');
// 报名人删除
export const userSignDel = (data: { id: number }) => request<UserSign.Config.Data[]>('/user_sign/del', 'POST', data);
// 报名人添加
export const userSignAdd = (data: Omit<SignTeam.Leader.Body, 'active_id' | 'title'>) =>
  request<UserSign.Config.Data[]>('/user_sign/add', 'POST', data);
// 报名人编辑
export const userSignEdit = (data: Omit<SignTeam.Leader.Body, 'active_id' | 'title'> & { id: number }) =>
  request<UserSign.Config.Data[]>('/user_sign/edit', 'POST', data);

// 队伍信息
export const getTeamInfo = (query: Partial<SignTeam.Info.Query>) =>
  request<SignTeam.Info.Data>('/sign_team/get_team_info', 'GET', query);
// 队员报名
export const signTeamMember = (data: Omit<SignTeam.Leader.Body, 'title'> & { invite_code: string }) =>
  request<null>('/sign_team/member', 'POST', data);
